package com.itzjc.domain.entity;

import java.io.Serializable;


/**
 * 封装返回结果类
 **/
public class Result implements Serializable {
    //执行结果，true为执行成功 false为执行失败
    private int code;
    //返回结果信息
    private String message;
    //返回数据
    private Object data;

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Result() {
    }

    public Result(String message) {
        this.message = message;
    }

    public Result(int code, Object data) {
        this.code = code;
        this.data = data;
    }

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    //操作成功返回数据，默认成功就是200，不用输入了
    public static Result buildSuccess(String message, Object data) {
        return new Result(200, message, data);
    }

    //操作失败，传递错误码，规范统一这个码的含义就行了
    public static Result buildError(String message, int code) {
        return new Result(code, message);
    }

    //操作失败的简单类型
    public static Result buildError(String message) {
        return new Result(message);
    }


    //操作成功也有返回简单数据的
    public static Result buildSuccess(String message) {
        return new Result(200, message);
    }
}
